home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / Cnet 2.60 d2.adf / programming / empty.c < prev    next >
C/C++ Source or Header  |  1993-02-10  |  10KB  |  503 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    CNet AMIGA 2.0  C language interface routines and examples    */
  4. /*                                    */
  5. /*    © 1991    Perspective Software ... this code may be freely    */
  6. /*        ditributed to and used by registered CNet owners    */
  7. /*        EXCLUSIVELY.  Other distribution is in violation     */
  8. /*        of copyright laws.                    */
  9. /*                                    */
  10. /************************************************************************/
  11.  
  12. void CallHost( UBYTE c );
  13. void ShutDown( char *spawn );
  14.  
  15. struct MsgPort  *replyp;    /* Some commnunication details ...    */
  16. struct CPort    *cport;
  17. struct CMessage  cmess;
  18.  
  19. struct    MainPort  *myp;        /* Pointer to CNet port--ALL info!    */
  20. struct    PortData  *z;
  21.  
  22. char    **bm;
  23. struct    SignalSemaphore *SEM;
  24.                 /* put your other GLOBALS here        */
  25.  
  26.  
  27. void main( int argc, char **argv )
  28. {
  29.     if( argc<2 || !(cport = (struct CPort *)FindPort( argv[1] )) ) {
  30.         printf("This is a CNet C program.\n");
  31.         exit(0);
  32.     }
  33.  
  34.     if( !(replyp = CreatePort( 0,0 )))
  35.         exit(0);
  36.  
  37.     cmess.cn_Message.mn_ReplyPort   = replyp;
  38.     cmess.cn_Message.mn_Length      = sizeof( struct CMessage );
  39.     cmess.cn_Message.mn_Node.ln_Name= "cstuff";
  40.  
  41.     if( cport->ack != 30 ) {    /* right CNet version running? */
  42.         cport->ack = 1;
  43.         goto err;
  44.     }
  45.  
  46.     cport->ack = 0;
  47.  
  48.     z        =    cport->zp;
  49.     myp        =    cport->myp;
  50.     SEM        =    myp->SEM;
  51.     bm        =    z->bm;
  52.  
  53.     /* put your program here */
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.     /* get back to CNet */
  61.  
  62.     ShutDown( NULL );
  63.  
  64. err:    DeletePort( replyp );
  65.     exit(0);
  66. }
  67.  
  68. void ShutDown( char *spawn )            /* another file to run? */
  69. {
  70.     if( spawn )
  71.         strcpy( z->CSpawn, spawn );
  72.  
  73.     CallHost( 0 );
  74. }
  75.  
  76. void CallHost( UBYTE c )
  77. {
  78.     cmess.command = c;
  79.     PutMsg  ( (struct MsgPort *)cport, (struct Message *)&cmess );
  80.     WaitPort( replyp );
  81.     GetMsg  ( replyp );
  82. }
  83.  
  84. void PutText( char *text )
  85. {
  86.     cmess.arg1 = (ULONG)text;    /* text to print        */
  87.     CallHost( 1 );
  88. }
  89.  
  90. void PutA( void )
  91. {
  92.     PutText( z->ABuffer );
  93. }
  94.  
  95. int EnterLine( UBYTE len, USHORT flags, char *prompt )
  96. {
  97.     cmess.arg1 = (ULONG)len;    /* how many chars max to input    */
  98.     cmess.arg2 = (ULONG)flags;    /* 1=UpperCase            */
  99.     cmess.arg3 = (ULONG)prompt;    /* text to print before input    */
  100.     CallHost( 2 );            /* result is in z->InBuffer    */
  101.     return( (int)strlen( z->InBuffer ));
  102. }
  103.  
  104. char GetKey( void )            /* Stop until a key is pressed    */
  105. {
  106.     CallHost( 3 );
  107.     return( (char)cmess.result );
  108. }
  109.  
  110. void EnterPassword( UBYTE len )
  111. {
  112.     cmess.arg1 = (ULONG)len;    /* max number of characters */
  113.     CallHost( 4 );
  114. }
  115.  
  116. long CommonCommands( void )        /* Check z->InBuffer for Chat, OLM, etc */
  117. {
  118.     CallHost( 5 );
  119.     return( (long)cmess.result );
  120. }
  121.  
  122. UBYTE ReadFile( char *path, UBYTE flags )
  123. {
  124.     cmess.arg1 = (ULONG)path;
  125.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  126.     CallHost( 6 );
  127.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  128. }
  129.  
  130. void SetDoing( char *what )
  131. {
  132.     cmess.arg1 = (ULONG)what;
  133.     CallHost( 7 );
  134. }
  135.  
  136. void CallEditor( short max, short inlines )
  137. {
  138.     cmess.arg1 = (ULONG)max;    /* Maximum number of lines (250)*/
  139.     cmess.arg2 = (ULONG)inlines;    /* TRUE/FALSE use existing _edbuff? */
  140.     CallHost( 8 );
  141. }
  142.  
  143. UBYTE ReadGraphics( char *path, char flags )
  144. {
  145.     cmess.arg1 = (ULONG)path;
  146.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  147.     CallHost( 9 );
  148.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  149. }
  150.  
  151. void MakeDate( struct IsDate *date, char *output )
  152. {
  153.     cmess.arg1 = (ULONG)date;
  154.     cmess.arg2 = (ULONG)output;
  155.     CallHost( 10 );
  156. }
  157.  
  158. void ReadAccount( short id, struct UserData *user )
  159. {
  160.     cmess.arg1 = (ULONG)id;
  161.     cmess.arg2 = (ULONG)user;
  162.     CallHost( 11 );
  163. }
  164.  
  165. void SaveUser( struct UserData *user, short id )
  166. {
  167.     cmess.arg1 = (ULONG)user;
  168.     cmess.arg2 = (ULONG)id;
  169.     CallHost( 12 );
  170. }
  171.  
  172. UBYTE AddCharge( short n, short a )
  173. {
  174.     cmess.arg1 = (ULONG)n;
  175.     cmess.arg2 = (ULONG)a;
  176.     CallHost( 13 );
  177.     return( (UBYTE)cmess.result );
  178. }
  179.  
  180. UBYTE CheckBalance( short n, short a )
  181. {
  182.     cmess.arg1 = (ULONG)n;
  183.     cmess.arg2 = (ULONG)a;
  184.     CallHost( 14 );
  185.     return( (UBYTE)cmess.result );
  186. }
  187.  
  188. int EnterText( char firstchar, short maxchars, short perline, short maxlines )
  189. {
  190.     cmess.arg1 = (ULONG)firstchar;
  191.     cmess.arg2 = (ULONG)maxchars;
  192.     cmess.arg3 = (ULONG)perline;
  193.     cmess.arg4 = (ULONG)maxlines;
  194.     CallHost( 15 );
  195.     return( (int)cmess.result );
  196. }
  197.  
  198. long ConferenceWait( short a )
  199. {
  200.     cmess.arg1 = (ULONG) a;
  201.     CallHost( 16 );
  202.     return( (long)cmess.result );
  203. }
  204.  
  205. void CheckChanges( void )
  206. {
  207.     CallHost( 17 );
  208. }
  209.  
  210. long ConvertAccess( char *s )
  211. {
  212.     cmess.arg1 = (ULONG)s;
  213.     CallHost( 18 );
  214.     return( (long)cmess.result );
  215. }
  216.  
  217. int GetFree( char *s, UBYTE q )
  218. {
  219.     cmess.arg1 = (ULONG)s;
  220.     cmess.arg2 = (ULONG)q;
  221.     CallHost( 19 );
  222.     return( (int)cmess.result );
  223. }
  224.  
  225. short FindAccount( char *a, struct UserData *b )
  226. {
  227.     cmess.arg1 = (ULONG)a;
  228.     cmess.arg2 = (ULONG)b;
  229.     CallHost( 20 );
  230.     return( (short)cmess.result );
  231. }
  232.  
  233. void CheckFlowControl( void )
  234. {
  235.     CallHost( 21 );
  236. }
  237.  
  238. int ListDir( UBYTE a, UBYTE b, struct IsDate *c )
  239. {
  240.     cmess.arg1 = (ULONG)a;
  241.     cmess.arg2 = (ULONG)b;
  242.     cmess.arg3 = (ULONG)c;
  243.     CallHost( 22 );
  244.     return( (int)cmess.result );
  245. }
  246.  
  247. UBYTE FileOLM( short a, int b )
  248. {
  249.     cmess.arg1 = (ULONG)a;
  250.     cmess.arg2 = (ULONG)b;
  251.     CallHost( 23 );
  252.     return( (UBYTE)cmess.result );
  253. }
  254.  
  255. UBYTE Rnext( void )
  256. {
  257.     CallHost( 24 );
  258.     return( (UBYTE)cmess.result );
  259. }
  260.  
  261. void ParseCommandLine( void )
  262. {
  263.     CallHost( 25 );
  264. }
  265.  
  266. short FindCommand( short num )
  267. {
  268.     cmess.arg1 = (ULONG) num;
  269.     CallHost( 26 );
  270.     return( (short)cmess.result );
  271. }
  272.  
  273. void ReadMessagePoint( char *a, long b )
  274. {
  275.     cmess.arg1 = (ULONG) a;
  276.     cmess.arg2 = (ULONG) b;
  277.     CallHost( 27 );
  278. }
  279.  
  280. void EditMessage( char *file )
  281. {
  282.     cmess.arg1 = (ULONG) file;
  283.     CallHost( 28 );
  284. }
  285.  
  286. void LoadText( BPTR fh )
  287. {
  288.     cmess.arg1 = (ULONG) fh;
  289.     CallHost( 29 );
  290. }
  291.  
  292. long GrabFileSize( UBYTE quiet )
  293. {
  294.     cmess.arg1 = (ULONG) quiet;
  295.     CallHost( 30 );
  296.     return( (long)cmess.result );
  297. }
  298.  
  299. char WaitForInput( long mics )
  300. {
  301.     cmess.arg1 = (ULONG) mics;
  302.     CallHost( 31 );
  303.     return( (char)cmess.result );
  304. }
  305.  
  306. void AddCredits( UBYTE justadd, short m )
  307. {
  308.     cmess.arg1 = (ULONG)justadd;
  309.     cmess.arg2 = (ULONG)m;
  310.     CallHost( 33 );
  311. }
  312.  
  313. UBYTE SelectAndDownload( char *file, UBYTE now )
  314. {
  315.     cmess.arg1 = (ULONG)file;
  316.     cmess.arg2 = (ULONG)now;
  317.     CallHost( 39 );
  318.     return( (UBYTE)cmess.result );
  319. }
  320.  
  321. /* file: the ".vde" filename, without the .VDE!
  322.    data: pointer to the structure you are going to edit
  323.    size: structure length in bytes
  324.  
  325.    returns: TRUE if structure has been changed
  326.         FALSE otherwise
  327. */
  328.  
  329. short VisualDataEditor( char *file, void *data, long size )
  330. {
  331.     cmess.arg1 = (ULONG)file;
  332.     cmess.arg2 = (ULONG)data;
  333.     cmess.arg3 = (ULONG)size;
  334.     CallHost( 40 );
  335.     return( (short)cmess.result );
  336. }
  337.  
  338. void WriteLog( short n, char *text1, char *text2 )
  339. {
  340.     cmess.arg1 = (ULONG)n;
  341.     cmess.arg2 = (ULONG)text1;
  342.     cmess.arg3 = (ULONG)text2;
  343.     CallHost( 41 );
  344. }
  345.  
  346. /* 
  347.     In preparation for an ExtUpload, this functions
  348.     sets the number minimum number of free bytes to maintain on the
  349.     drive.
  350. */
  351.  
  352. void ExtSetMinFree( long free )
  353. {
  354.     cmess.arg1 = (ULONG)free;
  355.     CallHost( 42 );
  356. }
  357.  
  358. /*
  359.     In preparation for an ExtDownload or an ExtUpload, this function
  360.     sets the protocol to be used.  If you send NULL, it will allow the
  361.     user to choose his OWN protocol.
  362.  
  363.     Otherwise, you may select 'a' to be the first letter of a valid
  364.     system protocol (from BBSPROTO file), such as 'x', 'z', etc.
  365.  
  366.     TRUE will be returned if a protocol is selected and ready, FALSE
  367.     if there is a problem.
  368. */
  369.  
  370. UBYTE ExtSetProtocol( char a )
  371. {
  372.     cmess.arg1 = (ULONG)a;
  373.     CallHost( 43 );
  374.     return( (UBYTE)cmess.result );
  375. }
  376.  
  377. /* 
  378.     This routine allows the user to download the SINGLE file specified
  379.     by the FULL PATH 'args'.
  380.  
  381.     Currently, NULL is always returned.
  382. */
  383.  
  384. char *ExtDownload( char *args )
  385. {
  386.     cmess.arg1 = (ULONG)args;
  387.     CallHost( 44 );
  388.     return( (char *)cmess.result );
  389. }
  390.  
  391. /*
  392.     This routine allows the user to upload the file specified by
  393.     'args'.  The path for uploading will be taken from the path
  394.     in 'args'.  If you do NOT specify a path, the file(s) will
  395.     appear in the user's HOME directory.
  396.  
  397.     Note that with batch protocols like ZMODEM, the filename(s) are
  398.     taken from the header packet information, and may NOT be the
  399.     same as what you have requested the user upload.  For this reason,
  400.     you should have uploads occur in a TEMP directory, and search that
  401.     directory yourself for new files.
  402.  
  403.     Currently, NULL is always returned.
  404. */
  405.  
  406. char *ExtUpload( char *args )
  407. {
  408.     cmess.arg1 = (ULONG)args;
  409.     CallHost( 45 );
  410.     return( (char *)cmess.result );
  411. }
  412.  
  413. /* some commonly used functions in CNet */
  414.  
  415. short compstra( char *s, char *t )
  416. {
  417.     for( ; tolower(*s) == tolower(*t); s++, t++)
  418.         if( !*s ) return 0;
  419.  
  420.     return( (short)(tolower(*s)-tolower(*t)) );
  421. }
  422.  
  423. UBYTE PutQ( char *a )
  424. {
  425.     PutText( a );
  426.     return (UBYTE)(z->MCIcreg[0][0]=='1') ;
  427. }
  428.  
  429. char *PrintAccess( int a, short n )
  430. {
  431.     short    i;
  432.     static    char list[25];
  433.  
  434.     for( i=0; i<n; i++ ) {
  435.         if ( a & 1<<i )
  436.             list[i] = i%10+48;
  437.         else    list[i] = '-';
  438.     }
  439.     list[n] = 0;
  440.  
  441.     return list;
  442. }
  443.  
  444. void DoReturn( void )
  445. {
  446.     PutText("\n");
  447. }
  448.  
  449. void MakeEd( char *path )
  450. {
  451.     sprintf( path, "%s_edbuff%d", myp->gc.ZIPpath, z->InPort );
  452. }
  453.  
  454. void DeleteEd( void )
  455. {
  456.     char    filename[80];
  457.  
  458.     MakeEd    ( filename ) ;
  459.     DeleteFile( filename ) ;
  460. }
  461.  
  462. BPTR OpenEd( long mode )
  463. {
  464.     char    filename[80];
  465.  
  466.     MakeEd( filename );
  467.  
  468.     return Open( filename, mode );
  469. }
  470.  
  471. void PrepEditor( BPTR fp )
  472. {
  473.     BPTR    kp;
  474.     char    buff[100];
  475.  
  476.     if( fp ) {
  477.         if( kp = OpenEd( MODE_NEWFILE ) ) {
  478.             while( FGets( fp, buff, 82 ) && buff[0]!=26 )
  479.                    FPuts( kp, buff     ) ;
  480.  
  481.             Close( kp );
  482.         }
  483.     }
  484.     else    DeleteEd();
  485. }
  486.  
  487. void SaveEditor( BPTR fp, UBYTE eof )
  488. {
  489.     BPTR    kp;
  490.     char    buff[100];
  491.  
  492.     if( kp = OpenEd( MODE_OLDFILE ) ) {
  493.         while( FGets( kp, buff, 82 ) && buff[0]!=26 )
  494.                FPuts( fp, buff     ) ;
  495.  
  496.         Close( kp );
  497.  
  498.         DeleteEd();
  499.     }
  500.  
  501.     if( eof ) FPuts( fp, "\032\n" );
  502. }
  503.